package com.android.drm;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;

/**
 * <p><b>CLASS:</b> com.android.drm.SplashScreen</p>
 *
 * ...........................................................................
 * <p><b>DESCRIPTION:</b><br/>
 * The first/splash screen for the application.
 * </p>
 * 
 * ...........................................................................
 * <p><b>MODIFICATION HISTORY:</b>
 * <p>[2010/08/03] michellem: Initial version.</p>
 * </p>
 * 
 * ...........................................................................
 * @author michellem
 * @since 1.0
 */

public class SplashScreen extends Activity {
    private boolean mActive = true;
    private int mSplashTime = 1; // in seconds
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        // Creates mediaplayer
    	MediaPlayer mp = MediaPlayer.create(SplashScreen.this, R.raw.test);
    	
        // Thread for displaying the SplashScreen
        Thread splashThread = new Thread() {
            @Override
            public void run() {           	
                try {
                    int waited = 0;
                    while (mActive && (waited < mSplashTime)) {
                        sleep(1000);
                        if (mActive) {
                            waited ++;;
                        }
                    }
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    finish();
                    startActivity(new Intent(SplashScreen.this, HomeScreen.class));
                    stop();
                }
            }
        };  
        splashThread.start();
        mp.start(); // starts music
    }
    
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mActive = false;
        }
        return true;
    }
}